home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / src / tempvars.c < prev    next >
Text File  |  1994-01-03  |  26KB  |  1,055 lines

  1. # include "TempVars.h"
  2. # include "yyTVars.w"
  3. # include <stdio.h>
  4. # if defined __STDC__ | defined __cplusplus
  5. #  include <stdlib.h>
  6. # else
  7.    extern void exit ();
  8. # endif
  9. # include "Tree.h"
  10. # include "Definiti.h"
  11.  
  12. # ifndef NULL
  13. # define NULL 0L
  14. # endif
  15. # ifndef false
  16. # define false 0
  17. # endif
  18. # ifndef true
  19. # define true 1
  20. # endif
  21.  
  22. # ifdef yyInline
  23. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) \
  24.   if ((ptr = (tree) free) >= (tree) max) ptr = alloc (); \
  25.   free += nodesize [kind]; \
  26.   ptr->yyHead.yyMark = 0; \
  27.   ptr->Kind = kind;
  28. # else
  29. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) ptr = make (kind);
  30. # endif
  31.  
  32. # define yyWrite(s) (void) fputs (s, yyf)
  33. # define yyWriteNl (void) fputc ('\n', yyf)
  34.  
  35. # line 27 "TempVars.puma"
  36.  
  37. # include "Idents.h"
  38. # include "StringMe.h"
  39. # include "protocol.h"
  40.  
  41.  
  42. # include "Transfor.h"  /* AppendDECLS, CombineACF */
  43. # include "Shapes.h"     /* IsWholeVar              */
  44.  
  45. typedef int *pint;
  46.  
  47. tTree new_decls;          /* global used for new declarations */
  48. int new_allocates;        /* counts globally new necessary allocates */
  49.  
  50. tTree new_assigns;        /* global used when creating the local */
  51. int TopLevel;             /* expression with movements           */
  52.  
  53.  
  54.  
  55. static FILE * yyf = stdout;
  56.  
  57. static void yyAbort
  58. # ifdef __cplusplus
  59.  (char * yyFunction)
  60. # else
  61.  (yyFunction) char * yyFunction;
  62. # endif
  63. {
  64.  (void) fprintf (stderr, "Error: module TempVars, routine %s failed\n", yyFunction);
  65.  exit (1);
  66. }
  67.  
  68. void TempVarsInitBody ARGS((tTree t));
  69. void TempVarsDoneBody ARGS((tTree t));
  70. tTree MakeLocalExpression ARGS((tTree exp, tTree var, int no, bool simple, int * needed, tTree * assigns));
  71. static void MakeTempStmt ARGS((tTree exp, tTree var, int no));
  72. static tTree NewTempExp ARGS((tTree exp, tTree var, int no, pint needed));
  73. static tTree NewTempCShift ARGS((tTree exp, tTree var, int no, pint needed));
  74. static tTree GetMajorityVar ARGS((tTree e));
  75. static tTree NewTempVar ARGS((tTree var, int no));
  76. static tTree NewTempVarObj ARGS((tDefinitions Obj, int no));
  77. static tDefinitions CopyObject ARGS((tDefinitions Obj, tIdent newname));
  78. static tDefinitions CopyDistribution ARGS((tDefinitions d));
  79. static void NewTempAllocates ARGS((tTree t));
  80. static tTree ExtendTempAllocates ARGS((tTree t));
  81. static int NoOfTemporaries ARGS((tTree t));
  82.  
  83. void TempVarsInitBody
  84. # if defined __STDC__ | defined __cplusplus
  85. (register tTree t)
  86. # else
  87. (t)
  88.  register tTree t;
  89. # endif
  90. {
  91.   if (t == NoTree) return;
  92.   if (t->Kind == kBODY_NODE) {
  93. # line 54 "TempVars.puma"
  94.   {
  95. # line 55 "TempVars.puma"
  96.    new_decls = mDECL_EMPTY ();
  97. # line 56 "TempVars.puma"
  98.    new_allocates = 0;
  99.   }
  100.    return;
  101.  
  102.   }
  103. # line 59 "TempVars.puma"
  104.   {
  105. # line 60 "TempVars.puma"
  106.    printf ("Illegal Call of TempVarsInitBody");
  107. # line 61 "TempVars.puma"
  108.    kill_in_protocol ();
  109.   }
  110.    return;
  111.  
  112. ;
  113. }
  114.  
  115. void TempVarsDoneBody
  116. # if defined __STDC__ | defined __cplusplus
  117. (register tTree t)
  118. # else
  119. (t)
  120.  register tTree t;
  121. # endif
  122. {
  123.   if (t == NoTree) return;
  124.   if (t->Kind == kBODY_NODE) {
  125. # line 72 "TempVars.puma"
  126.   {
  127. # line 74 "TempVars.puma"
  128.    tree_protocol ("This are the new temporaries : \n", new_decls);
  129. # line 75 "TempVars.puma"
  130.  t->BODY_NODE.DECLS = AppendDECLS (t->BODY_NODE.DECLS, new_decls);
  131.      if (new_allocates > 0)
  132.         NewTempAllocates (t->BODY_NODE.STATS);
  133.  
  134.   }
  135.    return;
  136.  
  137.   }
  138. # line 81 "TempVars.puma"
  139.   {
  140. # line 82 "TempVars.puma"
  141.    printf ("Illegal Call of TempVarsDoneBody");
  142. # line 83 "TempVars.puma"
  143.    kill_in_protocol ();
  144.   }
  145.    return;
  146.  
  147. ;
  148. }
  149.  
  150. tTree MakeLocalExpression
  151. # if defined __STDC__ | defined __cplusplus
  152. (register tTree exp, register tTree var, register int no, register bool simple, register int * needed, register tTree * assigns)
  153. # else
  154. (exp, var, no, simple, needed, assigns)
  155.  register tTree exp;
  156.  register tTree var;
  157.  register int no;
  158.  register bool simple;
  159.  register int * needed;
  160.  register tTree * assigns;
  161. # endif
  162. {
  163. # line 119 "TempVars.puma"
  164.  {
  165.   tTree newexp;
  166.   tTree newass;
  167.   int n;
  168.   {
  169. # line 121 "TempVars.puma"
  170.  
  171. # line 122 "TempVars.puma"
  172.  
  173. # line 123 "TempVars.puma"
  174.  
  175. # line 125 "TempVars.puma"
  176.  new_assigns = NoTree;
  177.       if (simple)
  178.           TopLevel = 0;
  179.         else
  180.           TopLevel = 1;
  181.       n = 0;
  182.       newexp = NewTempExp (exp, var, no, &n);
  183.       newass = new_assigns;
  184.  
  185.   }
  186.    * needed = n;
  187.    * assigns = newass;
  188.   {
  189.    return newexp;
  190.   }
  191.  }
  192.  
  193. }
  194.  
  195. static void MakeTempStmt
  196. # if defined __STDC__ | defined __cplusplus
  197. (register tTree exp, register tTree var, register int no)
  198. # else
  199. (exp, var, no)
  200.  register tTree exp;
  201.  register tTree var;
  202.  register int no;
  203. # endif
  204. {
  205. # line 147 "TempVars.puma"
  206.  
  207. tTree newvar, stmt;
  208.  
  209.   if (exp == NoTree) return;
  210.   if (var == NoTree) return;
  211. # line 151 "TempVars.puma"
  212.   {
  213. # line 152 "TempVars.puma"
  214.  stmt = mASSIGN_STMT (NewTempVar(var, no), exp);
  215.     stmt = mACF_BASIC (stmt);
  216.     new_assigns = CombineACF (new_assigns, mACF_LIST (stmt, NoTree));
  217.  
  218.   }
  219.    return;
  220.  
  221. ;
  222. }
  223.  
  224. static tTree NewTempExp
  225. # if defined __STDC__ | defined __cplusplus
  226. (register tTree exp, register tTree var, register int no, pint needed)
  227. # else
  228. (exp, var, no, needed)
  229.  register tTree exp;
  230.  register tTree var;
  231.  register int no;
  232.  pint needed;
  233. # endif
  234. {
  235. # line 169 "TempVars.puma"
  236.  
  237. int count1;
  238. int count2;
  239. tTree newexp, majvar;
  240. int hneeded;
  241. int htop;
  242.  
  243.   if (exp->Kind == kOP_EXP) {
  244. # line 183 "TempVars.puma"
  245.   {
  246. # line 184 "TempVars.puma"
  247.  TopLevel = 0;
  248.       count1 = CountMovements (var, exp->OP_EXP.OPND1);
  249.       count2 = CountMovements (var, exp->OP_EXP.OPND2);
  250.       if (count1 == 0)
  251.         { if (count2 != 0)
  252.             {
  253.               exp->OP_EXP.OPND2 = NewTempExp (exp->OP_EXP.OPND2, var, no, needed);
  254.             }
  255.         }
  256.       else
  257.         { if (count2 == 0)
  258.             {
  259.               exp->OP_EXP.OPND1 = NewTempExp (exp->OP_EXP.OPND1, var, no, needed);
  260.             }
  261.            else
  262.             {
  263.               hneeded = 0;
  264.               newexp = NewTempExp (exp->OP_EXP.OPND1, var, no, &hneeded);
  265.               if (hneeded > 1)
  266.                 {
  267.                   MakeTempStmt (newexp, var, no);
  268.                   exp->OP_EXP.OPND1 = mVAR_EXP (NewTempVar (var, no));
  269.                 }
  270.                else
  271.                   exp->OP_EXP.OPND1 = newexp;
  272.               *needed = 1;
  273.               exp->OP_EXP.OPND2 = NewTempExp (exp->OP_EXP.OPND2, var, no+1, needed);
  274.             }
  275.         }
  276.  
  277.   }
  278.    return exp;
  279.  
  280.   }
  281.   if (exp->Kind == kOP1_EXP) {
  282. # line 217 "TempVars.puma"
  283.   {
  284. # line 218 "TempVars.puma"
  285.  TopLevel = 0;
  286.  
  287.       exp->OP1_EXP.OPND = NewTempExp (exp->OP1_EXP.OPND, var, no, needed);
  288.  
  289.   }
  290.    return exp;
  291.  
  292.   }
  293.   if (exp->Kind == kFUNC_CALL_EXP) {
  294.   if (Definitions_IsType (exp->FUNC_CALL_EXP.FUNC_ID->PROC_OBJ.Object, kObject)) {
  295. # line 225 "TempVars.puma"
  296.   {
  297. # line 226 "TempVars.puma"
  298.  newexp = exp;
  299.       if (IsIntrFunc (exp))
  300.         { if (IntrFuncKind1 (exp->FUNC_CALL_EXP.FUNC_ID->PROC_OBJ.Ident)
  301.              || IntrFuncKindn (exp->FUNC_CALL_EXP.FUNC_ID->PROC_OBJ.Ident)
  302.              || IntrFuncKind2 (exp->FUNC_CALL_EXP.FUNC_ID->PROC_OBJ.Ident))
  303.             {
  304.               TopLevel = 0;
  305.               count1 = CountMovements (var, exp->FUNC_CALL_EXP.FUNC_PARAMS);
  306.               if (count1 > 0)
  307.                 exp->FUNC_CALL_EXP.FUNC_PARAMS = NewTempExp (exp->FUNC_CALL_EXP.FUNC_PARAMS, var, no, needed);
  308.             }
  309.            else if (exp->FUNC_CALL_EXP.FUNC_ID->PROC_OBJ.Ident == MakeIdent ("CSHIFT", 6))
  310.             {
  311.               if (!IsWholeVar (var))
  312.                 {
  313.                   majvar = GetMajorityVar (exp);
  314.                   if (!IsWholeVar (majvar))
  315.                      { error_protocol ("CSHIFT, no full arrays");
  316.                      }
  317.                   hneeded = 0;
  318.                   htop = TopLevel;
  319.                   TopLevel = 0;
  320.                   newexp = NewTempCShift (exp, majvar, 1, &hneeded);
  321.                   TopLevel = htop;
  322.  
  323.                   if (TopLevel != 1)
  324.                    { MakeTempStmt (newexp, var, no);
  325.                      newexp = mVAR_EXP (NewTempVar (var, no));
  326.                      *needed = *needed + 1;
  327.                    }
  328.                 }
  329.                else
  330.                 {
  331.                   newexp = NewTempCShift (exp, var, no, needed);
  332.                 }
  333.             }
  334.            else if (exp->FUNC_CALL_EXP.FUNC_ID->PROC_OBJ.Ident == MakeIdent ("SPREAD", 6))
  335.             { error_protocol ("SPREAD not handled for temporaries");
  336.               newexp = exp;
  337.             }
  338.            else if (IntrFuncRed (exp->FUNC_CALL_EXP.FUNC_ID->PROC_OBJ.Ident))
  339.             {
  340.               if (TopLevel != 1)
  341.                 { MakeTempStmt (exp, var, no);
  342.                   newexp = mVAR_EXP (NewTempVar (var, no));
  343.                   *needed = *needed + 1;
  344.                 }
  345.             }
  346.         }
  347.  
  348.   }
  349.    return newexp;
  350.  
  351.   }
  352.   }
  353.   if (exp->Kind == kVAR_EXP) {
  354. # line 277 "TempVars.puma"
  355.   {
  356. # line 279 "TempVars.puma"
  357.  if ( (CountMovements (var, exp) != 0) && (TopLevel != 1))
  358.        {
  359.          MakeTempStmt (exp, var, no);
  360.          newexp = mVAR_EXP (NewTempVar (var, no));
  361.          *needed = *needed + 1;
  362.        }
  363.       else
  364.          newexp = exp;
  365.  
  366.   }
  367.    return newexp;
  368.  
  369.   }
  370.   if (exp->Kind == kBTP_LIST) {
  371.   if (exp->BTP_LIST.Elem->Kind == kVAR_PARAM) {
  372.   if (exp->BTP_LIST.Elem->VAR_PARAM.V->Kind == kADDR) {
  373. # line 291 "TempVars.puma"
  374.   {
  375. # line 292 "TempVars.puma"
  376.  count1 = CountMovements (var, exp->BTP_LIST.Elem->VAR_PARAM.V->ADDR.E);
  377.       if (count1 != 0)
  378.        {
  379.          exp->BTP_LIST.Elem->VAR_PARAM.V->ADDR.E = NewTempExp (exp->BTP_LIST.Elem->VAR_PARAM.V->ADDR.E,var,no,needed);
  380.          exp->BTP_LIST.Next = NewTempExp (exp->BTP_LIST.Next, var, no+1, needed);
  381.        }
  382.       else
  383.          exp->BTP_LIST.Next = NewTempExp (exp->BTP_LIST.Next, var, no, needed);
  384.  
  385.   }
  386.    return exp;
  387.  
  388.   }
  389. # line 304 "TempVars.puma"
  390.   {
  391. # line 305 "TempVars.puma"
  392.  count1 = CountMovements (var, exp->BTP_LIST.Elem->VAR_PARAM.V);
  393.       if (count1 != 0)
  394.        {
  395.          newexp = mVAR_EXP (exp->BTP_LIST.Elem->VAR_PARAM.V);
  396.          newexp = NewTempExp (newexp, var, no, needed);
  397.          if (newexp->Kind != kVAR_EXP)
  398.            { printf ("Unknown Parameter Error in NewTempExp\n");
  399.              WriteTree (stdout, newexp);
  400.              exit (-1);
  401.            }
  402.          exp->BTP_LIST.Elem->VAR_PARAM.V = newexp->VAR_EXP.V;
  403.          exp->BTP_LIST.Next = NewTempExp (exp->BTP_LIST.Next, var, no+1, needed);
  404.        }
  405.       else
  406.          exp->BTP_LIST.Next = NewTempExp (exp->BTP_LIST.Next, var, no, needed);
  407.  
  408.   }
  409.    return exp;
  410.  
  411.   }
  412.   }
  413.   if (exp->Kind == kBTP_EMPTY) {
  414. # line 325 "TempVars.puma"
  415.    return exp;
  416.  
  417.   }
  418. # line 329 "TempVars.puma"
  419.   {
  420. # line 330 "TempVars.puma"
  421.    printf ("NewTempExp failed, no = %d\n", no);
  422. # line 331 "TempVars.puma"
  423.    printf ("exp = ");
  424. # line 331 "TempVars.puma"
  425.    FileUnparse (stdout, exp);
  426. # line 331 "TempVars.puma"
  427.    printf ("\n");
  428. # line 332 "TempVars.puma"
  429.    exit (- 1);
  430.   }
  431.    return exp;
  432.  
  433. }
  434.  
  435. static tTree NewTempCShift
  436. # if defined __STDC__ | defined __cplusplus
  437. (register tTree exp, register tTree var, register int no, pint needed)
  438. # else
  439. (exp, var, no, needed)
  440.  register tTree exp;
  441.  register tTree var;
  442.  register int no;
  443.  pint needed;
  444. # endif
  445. {
  446. # line 340 "TempVars.puma"
  447.  
  448. tTree newexp;
  449. int htop;
  450.  
  451.   if (exp->Kind == kFUNC_CALL_EXP) {
  452.   if (exp->FUNC_CALL_EXP.FUNC_PARAMS->Kind == kBTP_LIST) {
  453.   if (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->Kind == kVAR_PARAM) {
  454.   if (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V->Kind == kADDR) {
  455. # line 349 "TempVars.puma"
  456.   {
  457. # line 352 "TempVars.puma"
  458.  
  459.       htop = TopLevel;
  460.       TopLevel = 0;
  461.       exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V->ADDR.E = NewTempExp (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V->ADDR.E, var, no, needed);
  462.       TopLevel = htop;
  463.       if (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V->ADDR.E->Kind == kVAR_EXP)
  464.          exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V = exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V->ADDR.E->VAR_EXP.V;
  465.       if (TopLevel != 1)
  466.         { MakeTempStmt (exp, var, no);
  467.           newexp = mVAR_EXP (NewTempVar (var, no));
  468.           *needed = *needed + 1;
  469.         }
  470.        else
  471.           newexp = exp;
  472.  
  473.   }
  474.    return newexp;
  475.  
  476.   }
  477. # line 374 "TempVars.puma"
  478.   {
  479. # line 376 "TempVars.puma"
  480.  if (!IsWholeVar  (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V))
  481.         {
  482.           MakeTempStmt (mVAR_EXP(exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V), var, no);
  483.           exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V = NewTempVar (var, no);
  484.  
  485.         }
  486.  
  487.       if (TopLevel != 1)
  488.        { MakeTempStmt (exp, var, no);
  489.          newexp = mVAR_EXP (NewTempVar (var, no));
  490.          *needed = *needed + 1;
  491.        }
  492.        else
  493.           newexp = exp;
  494.  
  495.   }
  496.    return newexp;
  497.  
  498.   }
  499.   }
  500.   }
  501.  yyAbort ("NewTempCShift");
  502. }
  503.  
  504. static tTree GetMajorityVar
  505. # if defined __STDC__ | defined __cplusplus
  506. (register tTree e)
  507. # else
  508. (e)
  509.  register tTree e;
  510. # endif
  511. {
  512.   if (e->Kind == kVAR_PARAM) {
  513.   if (e->VAR_PARAM.V->Kind == kADDR) {
  514. # line 402 "TempVars.puma"
  515.    return GetMajorityVar (e->VAR_PARAM.V->ADDR.E);
  516.  
  517.   }
  518. # line 406 "TempVars.puma"
  519.    return e->VAR_PARAM.V;
  520.  
  521.   }
  522.   if (e->Kind == kFUNC_CALL_EXP) {
  523.   if (equaltIdent (e->FUNC_CALL_EXP.FUNC_ID->PROC_OBJ.Ident, MakeIdent ("CSHIFT", 6))) {
  524.   if (e->FUNC_CALL_EXP.FUNC_PARAMS->Kind == kBTP_LIST) {
  525. # line 410 "TempVars.puma"
  526.    return GetMajorityVar (e->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem);
  527.  
  528.   }
  529.   }
  530.   }
  531. # line 415 "TempVars.puma"
  532.   {
  533. # line 416 "TempVars.puma"
  534.    printf ("GetMajorityVar failes\n");
  535. # line 417 "TempVars.puma"
  536.    FileUnparse (stdout, e);
  537. # line 417 "TempVars.puma"
  538.    printf ("\n");
  539. # line 418 "TempVars.puma"
  540.    WriteTree (stdout, e);
  541. # line 419 "TempVars.puma"
  542.    exit (- 1);
  543.   }
  544.    return NoTree;
  545.  
  546. }
  547.  
  548. static tTree NewTempVar
  549. # if defined __STDC__ | defined __cplusplus
  550. (register tTree var, register int no)
  551. # else
  552. (var, no)
  553.  register tTree var;
  554.  register int no;
  555. # endif
  556. {
  557. # line 433 "TempVars.puma"
  558.  
  559. tTree newvar;
  560.  
  561.   if (equalint (no, 0)) {
  562. # line 437 "TempVars.puma"
  563.    return (CopyTree (var));
  564.  
  565.   }
  566.   if (var->Kind == kUSED_VAR) {
  567. # line 441 "TempVars.puma"
  568.   {
  569. # line 442 "TempVars.puma"
  570.  
  571.      newvar = NewTempVarObj (var->USED_VAR.VARNAME->VAR_OBJ.Object, no);
  572.      newvar = mUSED_VAR (newvar);
  573.  
  574.   }
  575.    return (newvar);
  576.  
  577.   }
  578.   if (var->Kind == kINDEXED_VAR) {
  579.   if (var->INDEXED_VAR.IND_VAR->Kind == kUSED_VAR) {
  580. # line 449 "TempVars.puma"
  581.   {
  582. # line 450 "TempVars.puma"
  583.  
  584.      newvar = NewTempVarObj (var->INDEXED_VAR.IND_VAR->USED_VAR.VARNAME->VAR_OBJ.Object, no);
  585.      newvar = mUSED_VAR (newvar);
  586.      newvar = mINDEXED_VAR (newvar, CopyTree (var->INDEXED_VAR.IND_EXPS));
  587.  
  588.   }
  589.    return (newvar);
  590.  
  591.   }
  592.   }
  593.  yyAbort ("NewTempVar");
  594. }
  595.  
  596. static tTree NewTempVarObj
  597. # if defined __STDC__ | defined __cplusplus
  598. (register tDefinitions Obj, register int no)
  599. # else
  600. (Obj, no)
  601.  register tDefinitions Obj;
  602.  register int no;
  603. # endif
  604. {
  605. # line 468 "TempVars.puma"
  606.  
  607. char string1[100], string2[100];
  608. tIdent newname;
  609. tTree t;
  610. tObject newobj;
  611.  
  612.   if (Obj->Kind == kVarObject) {
  613. # line 475 "TempVars.puma"
  614.   {
  615. # line 476 "TempVars.puma"
  616.  GetString (Obj->VarObject.ident, string1);
  617.      sprintf (string2, "%s_TMP%d", string1, no);
  618.      newname = MakeIdent (string2, strlen (string2));
  619.      if (no <= Obj->VarObject.Dist->Distribution.helpvars)
  620.        {
  621.          newobj = GetLocalDecl (newname);
  622.          if (newobj == NoObject)
  623.            { printf ("New Object %s not found \n", string2);
  624.              exit (-1);
  625.            }
  626.          t = mVAR_OBJ (0, newname);
  627.          t->VAR_OBJ.Object = newobj;
  628.        }
  629.      else
  630.        {
  631.          if (no != Obj->VarObject.Dist->Distribution.helpvars + 1)
  632.            { printf ("ERROR: no = %d, helps = %d\n", no, Obj->VarObject.Dist->Distribution.helpvars);
  633.              exit (-1);
  634.            }
  635.          Obj->VarObject.Dist->Distribution.helpvars = no;
  636.          newobj = CopyObject (Obj, newname);
  637.          t = mVAR_OBJ (0, newname);
  638.          t->VAR_OBJ.Object = newobj;
  639.        }
  640.  
  641.   }
  642.    return t;
  643.  
  644.   }
  645.  yyAbort ("NewTempVarObj");
  646. }
  647.  
  648. static tDefinitions CopyObject
  649. # if defined __STDC__ | defined __cplusplus
  650. (register tDefinitions Obj, register tIdent newname)
  651. # else
  652. (Obj, newname)
  653.  register tDefinitions Obj;
  654.  register tIdent newname;
  655. # endif
  656. {
  657. # line 514 "TempVars.puma"
  658.  
  659. tObject newobj;
  660. tTree newdecl;
  661. char string[100];
  662.  
  663.   if (Obj->Kind == kVarObject) {
  664.   if (Obj->VarObject.decl->Kind == kVAR_DECL) {
  665.   if (Obj->VarObject.Kind->Kind == kVarLocal) {
  666. # line 520 "TempVars.puma"
  667.   {
  668. # line 522 "TempVars.puma"
  669.    if (! (Obj->VarObject.ident == Obj->VarObject.decl->VAR_DECL.Name)) goto yyL1;
  670.   {
  671. # line 523 "TempVars.puma"
  672.  newdecl = mVAR_DECL (newname, Obj->VarObject.decl->VAR_DECL.Pos, CopyTree (Obj->VarObject.decl->VAR_DECL.VAL));
  673.      new_decls = mDECL_LIST (newdecl, new_decls);
  674.      newobj = mVarObject (newname, newdecl,
  675.               mVarLocal (0,Obj->VarObject.Kind->VarLocal.dynamic), 0, CopyDistribution (Obj->VarObject.Dist));
  676.      InsertEntry (newobj);
  677.      if (IsVarAllocatable (newobj))
  678.        {
  679.          new_allocates += 1;
  680.        }
  681.  
  682.   }
  683.   }
  684.    return newobj;
  685. yyL1:;
  686.  
  687.   }
  688.   if (Obj->VarObject.Kind->Kind == kVarCommon) {
  689. # line 536 "TempVars.puma"
  690.   {
  691. # line 538 "TempVars.puma"
  692.    if (! (Obj->VarObject.ident == Obj->VarObject.decl->VAR_DECL.Name)) goto yyL2;
  693.   {
  694. # line 539 "TempVars.puma"
  695.  newdecl = mVAR_DECL (newname, Obj->VarObject.decl->VAR_DECL.Pos, CopyTree (Obj->VarObject.decl->VAR_DECL.VAL));
  696.      new_decls = mDECL_LIST (newdecl, new_decls);
  697.      newobj = mVarObject (newname, newdecl,
  698.               mVarLocal (0,0), 0, CopyDistribution (Obj->VarObject.Dist));
  699.      InsertEntry (newobj);
  700.      if (IsVarAllocatable (newobj))
  701.        {
  702.          new_allocates += 1;
  703.        }
  704.  
  705.   }
  706.   }
  707.    return newobj;
  708. yyL2:;
  709.  
  710.   }
  711.   }
  712.   if (Obj->VarObject.decl->Kind == kVAR_PARAM_DECL) {
  713.   if (Obj->VarObject.Kind->Kind == kVarDummy) {
  714. # line 552 "TempVars.puma"
  715.   {
  716. # line 555 "TempVars.puma"
  717.    if (! (Obj->VarObject.decl->VAR_PARAM_DECL.Name == Obj->VarObject.ident)) goto yyL3;
  718.   {
  719. # line 556 "TempVars.puma"
  720.  newdecl = mVAR_DECL (newname, Obj->VarObject.decl->VAR_PARAM_DECL.Pos, CopyTree (Obj->VarObject.decl->VAR_PARAM_DECL.VAL));
  721.      new_decls = mDECL_LIST (newdecl, new_decls);
  722.      newobj = mVarObject (newname, newdecl,
  723.               mVarLocal (0,Obj->VarObject.Kind->VarDummy.dynamic), 0, CopyDistribution (Obj->VarObject.Dist));
  724.      InsertEntry (newobj);
  725.      if (IsVarAllocatable (newobj))
  726.        {
  727.          new_allocates += 1;
  728.        }
  729.  
  730.   }
  731.   }
  732.    return newobj;
  733. yyL3:;
  734.  
  735.   }
  736.   }
  737. # line 569 "TempVars.puma"
  738.   {
  739. # line 571 "TempVars.puma"
  740.    GetString (Obj->VarObject.ident, string);
  741. # line 572 "TempVars.puma"
  742.    obj_error_protocol ("Copy object fails for VarObject", Obj);
  743.   }
  744.    return Obj;
  745.  
  746.   }
  747. # line 576 "TempVars.puma"
  748.   {
  749. # line 577 "TempVars.puma"
  750.    obj_error_protocol ("Copy Object fails, unknown reasons", Obj);
  751.   }
  752.    return Obj;
  753.  
  754. }
  755.  
  756. static tDefinitions CopyDistribution
  757. # if defined __STDC__ | defined __cplusplus
  758. (register tDefinitions d)
  759. # else
  760. (d)
  761.  register tDefinitions d;
  762. # endif
  763. {
  764.   if (d->Kind == kHostDistribution) {
  765. # line 583 "TempVars.puma"
  766.    return mHostDistribution (d->HostDistribution.size, d->HostDistribution.helpvars, d->HostDistribution.hostdist_id);
  767.  
  768.   }
  769.   if (d->Kind == kNodeDistribution) {
  770. # line 587 "TempVars.puma"
  771.    return mNodeDistribution (d->NodeDistribution.size, d->NodeDistribution.helpvars, d->NodeDistribution.nodedist_id, d->NodeDistribution.dims);
  772.  
  773.   }
  774.   if (d->Kind == kSerialDistribution) {
  775. # line 591 "TempVars.puma"
  776.    return mSerialDistribution (d->SerialDistribution.size, d->SerialDistribution.helpvars);
  777.  
  778.   }
  779.   if (d->Kind == kAlignDistribution) {
  780. # line 595 "TempVars.puma"
  781.   {
  782. # line 596 "TempVars.puma"
  783.    printf ("AdaptTemporary: Copy Distribution\n");
  784. # line 597 "TempVars.puma"
  785.    printf ("Align Distribution should no longer exist here\n");
  786. # line 598 "TempVars.puma"
  787.    kill_in_protocol ();
  788.   }
  789.    return d;
  790.  
  791.   }
  792.  yyAbort ("CopyDistribution");
  793. }
  794.  
  795. static void NewTempAllocates
  796. # if defined __STDC__ | defined __cplusplus
  797. (register tTree t)
  798. # else
  799. (t)
  800.  register tTree t;
  801. # endif
  802. {
  803. # line 610 "TempVars.puma"
  804.  
  805. tObject Obj;
  806.  
  807.   if (t == NoTree) return;
  808.   if (t->Kind == kACF_LIST) {
  809. # line 614 "TempVars.puma"
  810.   {
  811. # line 615 "TempVars.puma"
  812.    NewTempAllocates (t->ACF_LIST.Elem);
  813. # line 616 "TempVars.puma"
  814.    NewTempAllocates (t->ACF_LIST.Next);
  815.   }
  816.    return;
  817.  
  818.   }
  819.   if (t->Kind == kACF_EMPTY) {
  820. # line 619 "TempVars.puma"
  821.    return;
  822.  
  823.   }
  824.   if (t->Kind == kACF_BASIC) {
  825.  
  826.   switch (t->ACF_BASIC.BASIC_STMT->Kind) {
  827.   case kIO_STMT:
  828. # line 622 "TempVars.puma"
  829.    return;
  830.  
  831.   case kALLOCATE_STMT:
  832. # line 625 "TempVars.puma"
  833.   {
  834. # line 626 "TempVars.puma"
  835.  t->ACF_BASIC.BASIC_STMT->ALLOCATE_STMT.PARAMS = ExtendTempAllocates (t->ACF_BASIC.BASIC_STMT->ALLOCATE_STMT.PARAMS);
  836.   }
  837.    return;
  838.  
  839.   case kDEALLOCATE_STMT:
  840. # line 629 "TempVars.puma"
  841.   {
  842. # line 630 "TempVars.puma"
  843.  t->ACF_BASIC.BASIC_STMT->DEALLOCATE_STMT.PARAMS = ExtendTempAllocates (t->ACF_BASIC.BASIC_STMT->DEALLOCATE_STMT.PARAMS);
  844.   }
  845.    return;
  846.  
  847.   case kCALL_STMT:
  848. # line 633 "TempVars.puma"
  849.    return;
  850.  
  851.   case kSTOP_STMT:
  852. # line 636 "TempVars.puma"
  853.    return;
  854.  
  855.   case kGOTO_STMT:
  856. # line 639 "TempVars.puma"
  857.    return;
  858.  
  859.   case kCOMP_IF_STMT:
  860. # line 642 "TempVars.puma"
  861.    return;
  862.  
  863.   case kASSIGN_STMT:
  864. # line 645 "TempVars.puma"
  865.    return;
  866.  
  867.   }
  868.  
  869. # line 648 "TempVars.puma"
  870.    return;
  871.  
  872.   }
  873.  
  874.   switch (t->Kind) {
  875.   case kACF_DUMMY:
  876. # line 651 "TempVars.puma"
  877.    return;
  878.  
  879.   case kACF_WHILE:
  880. # line 654 "TempVars.puma"
  881.   {
  882. # line 655 "TempVars.puma"
  883.    NewTempAllocates (t->ACF_WHILE.WHILE_BODY);
  884.   }
  885.    return;
  886.  
  887.   case kACF_DO:
  888. # line 658 "TempVars.puma"
  889.   {
  890. # line 659 "TempVars.puma"
  891.    NewTempAllocates (t->ACF_DO.DO_BODY);
  892.   }
  893.    return;
  894.  
  895.   case kACF_DOLOCAL:
  896. # line 662 "TempVars.puma"
  897.   {
  898. # line 663 "TempVars.puma"
  899.    NewTempAllocates (t->ACF_DOLOCAL.DOLOCAL_BODY);
  900.   }
  901.    return;
  902.  
  903.   case kACF_IF:
  904. # line 666 "TempVars.puma"
  905.   {
  906. # line 667 "TempVars.puma"
  907.    NewTempAllocates (t->ACF_IF.THEN_PART);
  908. # line 668 "TempVars.puma"
  909.    NewTempAllocates (t->ACF_IF.ELSE_PART);
  910.   }
  911.    return;
  912.  
  913.   case kACF_WHERE:
  914. # line 671 "TempVars.puma"
  915.   {
  916. # line 672 "TempVars.puma"
  917.    NewTempAllocates (t->ACF_WHERE.TRUE_PART);
  918. # line 673 "TempVars.puma"
  919.    NewTempAllocates (t->ACF_WHERE.FALSE_PART);
  920.   }
  921.    return;
  922.  
  923.   case kACF_NODE:
  924.   case kACF_BASIC:
  925.   case kACF_SWITCH:
  926.   case kACF_ALTER:
  927.   case kACF_CASE:
  928.   case kACF_REPEAT:
  929.   case kACF_WITH:
  930.   case kACF_LOOP:
  931.   case kACF_DOVEC:
  932.   case kACF_DOALL:
  933.   case kACF_FORALL:
  934.   case kACF_ON:
  935.   case kACF_BODY:
  936.   case kACF_FLOW_GRAPH:
  937.   case kACF_ENTRY:
  938. # line 676 "TempVars.puma"
  939.    return;
  940.  
  941.   }
  942.  
  943. # line 679 "TempVars.puma"
  944.   {
  945. # line 680 "TempVars.puma"
  946.    printf ("NewTempAllocates failed\n");
  947. # line 681 "TempVars.puma"
  948.    WriteTree (stdout, t);
  949. # line 682 "TempVars.puma"
  950.    exit (- 1);
  951.   }
  952.    return;
  953.  
  954. ;
  955. }
  956.  
  957. static tTree ExtendTempAllocates
  958. # if defined __STDC__ | defined __cplusplus
  959. (register tTree t)
  960. # else
  961. (t)
  962.  register tTree t;
  963. # endif
  964. {
  965. # line 687 "TempVars.puma"
  966.  
  967. tTree newp, liste;
  968. int count, i;
  969. tIdent name, newname;
  970. char string1[100], string2[100];
  971.  
  972.   if (t->Kind == kBTP_LIST) {
  973.   if (t->BTP_LIST.Elem->Kind == kVAR_PARAM) {
  974.   if (t->BTP_LIST.Elem->VAR_PARAM.V->Kind == kUSED_VAR) {
  975. # line 700 "TempVars.puma"
  976.   {
  977. # line 701 "TempVars.puma"
  978.  t->BTP_LIST.Next = ExtendTempAllocates (t->BTP_LIST.Next);
  979.        liste = t;
  980.        name = TreeVarName (t->BTP_LIST.Elem->VAR_PARAM.V->USED_VAR.VARNAME);
  981.        GetString (name, string1);
  982.        count = NoOfTemporaries (t->BTP_LIST.Elem->VAR_PARAM.V->USED_VAR.VARNAME);
  983.        for (i=1;i<=count;i++)
  984.           { sprintf (string2, "%s_TMP%d", string1, i);
  985.             newname = MakeIdent (string2, strlen (string2));
  986.             newp = mVAR_OBJ (0, newname);
  987.             newp->VAR_OBJ.Object = GetLocalDecl (newname);
  988.             newp = mVAR_PARAM (mUSED_VAR (newp));
  989.             liste = mBTP_LIST (newp, liste);
  990.           }
  991.  
  992.   }
  993.    return liste;
  994.  
  995.   }
  996.   if (t->BTP_LIST.Elem->VAR_PARAM.V->Kind == kINDEXED_VAR) {
  997.   if (t->BTP_LIST.Elem->VAR_PARAM.V->INDEXED_VAR.IND_VAR->Kind == kUSED_VAR) {
  998. # line 724 "TempVars.puma"
  999.   {
  1000. # line 725 "TempVars.puma"
  1001.  liste = ExtendTempAllocates (t->BTP_LIST.Next);
  1002.        name = TreeVarName (t->BTP_LIST.Elem->VAR_PARAM.V->INDEXED_VAR.IND_VAR->USED_VAR.VARNAME);
  1003.        GetString (name, string1);
  1004.        count = NoOfTemporaries (t->BTP_LIST.Elem->VAR_PARAM.V->INDEXED_VAR.IND_VAR->USED_VAR.VARNAME);
  1005.        for (i=count;i>0;i--)
  1006.           { sprintf (string2, "%s_TMP%d", string1, i);
  1007.             newname = MakeIdent (string2, strlen (string2));
  1008.             newp = mVAR_OBJ (0, newname);
  1009.             newp->VAR_OBJ.Object = GetLocalDecl (newname);
  1010.             newp = mINDEXED_VAR (mUSED_VAR(newp), CopyTree (t->BTP_LIST.Elem->VAR_PARAM.V->INDEXED_VAR.IND_EXPS));
  1011.             liste = mBTP_LIST (mVAR_PARAM (newp), liste);
  1012.           }
  1013.        t->BTP_LIST.Next = liste;
  1014.  
  1015.   }
  1016.    return t;
  1017.  
  1018.   }
  1019.   }
  1020.   }
  1021.   }
  1022.   if (t->Kind == kBTP_EMPTY) {
  1023. # line 742 "TempVars.puma"
  1024.    return t;
  1025.  
  1026.   }
  1027.  yyAbort ("ExtendTempAllocates");
  1028. }
  1029.  
  1030. static int NoOfTemporaries
  1031. # if defined __STDC__ | defined __cplusplus
  1032. (register tTree t)
  1033. # else
  1034. (t)
  1035.  register tTree t;
  1036. # endif
  1037. {
  1038.   if (t->Kind == kVAR_OBJ) {
  1039.   if (t->VAR_OBJ.Object->Kind == kVarObject) {
  1040. # line 748 "TempVars.puma"
  1041.    return t->VAR_OBJ.Object->VarObject.Dist->Distribution.helpvars;
  1042.  
  1043.   }
  1044.   }
  1045.  yyAbort ("NoOfTemporaries");
  1046. }
  1047.  
  1048. void BeginTempVars ()
  1049. {
  1050. }
  1051.  
  1052. void CloseTempVars ()
  1053. {
  1054. }
  1055.